unit uniEnemyAircraft_RayGun;

interface

uses
  uniEnemyAircraft,
  Classes;

type
  { EnemyAircraft_RayGun }

  EnemyAircraft_RayGun = class(EnemyAircraft)
  public
    constructor Create(et: EnemyType; p: array of Single; randFact: Single = 1.0);
    destructor Destroy; override;

    procedure update;override;
    procedure init; overload;override;
    procedure init(p: array of Single; randFact: Single = 1.0); overload;override;
    procedure move;override;
  end;


implementation

uses
  uniConfig,
  uniGlobal;

{ EnemyAircraft_RayGun }

constructor EnemyAircraft_RayGun.Create(et: EnemyType; p: array of Single; randFact: Single);
begin
  inherited Create(et, p, randFact);
  init(p, randFact);
end;

destructor EnemyAircraft_RayGun.Destroy;
begin
  inherited;
end;

procedure EnemyAircraft_RayGun.init;
begin
  inherited init;
end;

procedure EnemyAircraft_RayGun.init(p: array of Single; randFact: Single);
begin
  inherited init(p, randFact);

  damage := -1000.0 * uniGlobal.gameSkill;
  baseDamage := -1000.0 * uniGlobal.gameSkill;
  size[0] := 1.2;
  size[1] := 1.2;
  collisionMove := 0.2;
  vel[1] := 0.03;
  randMoveX := 0.5 + 0.5 * randMoveX;
end;

procedure EnemyAircraft_RayGun.move;
var
  _config: Config;
  hpos: PSingle;
  diff: array[0..1] of Single;
  tmpd, tmps: Single;
begin
  _config := uniConfig.instance;

  if Boolean(target) then
    hpos := target.getPos
  else
    hpos := @pos;
  //float	diff[2] := { hpos[0]-pos[0], hpos[1]-pos[1] };
  diff[0] := hpos^ - pos[0]; Inc(hpos);
  diff[1] := hpos^ - pos[1];
  tmpd := 0.0;
  tmps := 0.0;
  tmpd := Abs(diff[0]);
  if (tmpd < 3.0) then
    tmps := ((3.0 - tmpd) / 3.0) * (0.1 * sin(age * 0.25));
  if (Abs(diff[1]) < 7.0) then diff[1] := diff[1] * 0.1;
  lastMoveX := (0.975 * lastMoveX) + (0.0020 * diff[0]);
  lastMoveY := (0.90 * lastMoveY) + (0.001 * diff[1]);
  pos[0] := pos[0] + uniGlobal.speedAdj * (randMoveX * lastMoveX * (uniGlobal.gameSkill + 0.1) + tmps);
  pos[1] := pos[1] + uniGlobal.speedAdj * (lastMoveY + vel[1] * (uniGlobal.gameSkill + 0.1));

  if (pos[0] < -_config.screenBoundX) then pos[0] := -_config.screenBoundX;
  if (pos[0] > _config.screenBoundX) then pos[0] := _config.screenBoundX;
end;

//-- NOTE: Many of the firing rates are not adjusted by game->speedAdj
//-- so they will not be totally correct. Should be close enough for jazz, though.
//----------------------------------------------------------

procedure EnemyAircraft_RayGun.update;
var
  v, p: array[0..2] of Single;
  hpos: PSingle;
  a, s: Single;
begin
  //float	v[3] = { 0.0, -0.2, 0.0 };
  v[0] := 0.0;
  v[1] := -0.2;
  v[2] := 0.0;
  hpos := uniGlobal._hero.getPos;
  a := hpos^ - pos[0];
  //-- update age
  Inc(age);
  Dec(shootInterval);

  pos[0] := pos[0] + secondaryMove[0] * uniGlobal.speedAdj;
  pos[1] := pos[1] + secondaryMove[1] * uniGlobal.speedAdj;
  s := (1.0 - uniGlobal.speedAdj) + (uniGlobal.speedAdj * 0.7);
  secondaryMove[0] := secondaryMove[0] * s;
  secondaryMove[1] := secondaryMove[1] * s;
  move();

  //float	p[3] := { pos[0], pos[1], pos[2] };
  p[0] := pos[0];
  p[1] := pos[1];
  p[2] := pos[2];

  if (Abs(a) < 1.5) then //-- big center gun
  begin
    v[1] := -0.6;
    p[1] := pos[1] - 0.5;
    uniGlobal._enemyAmmo.addAmmo(3, p, v);
  end;
end;

end.

